package com.fhz.contentprivoder

import android.annotation.SuppressLint
import android.content.ContentValues
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.fhz.contentprivoder.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    lateinit var uri:Uri


    @SuppressLint("Range")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val inflate = ActivityMainBinding.inflate(layoutInflater)
        setContentView(inflate.root)

        //拿到内容提供者的提供
        uri= Uri.parse("content://com.feng.a2102")

        inflate.find.setOnClickListener{

            val contentValues = ContentValues()
            contentValues.put("categoryId",1)
            contentValues.put("goodsBanner",1)
            contentValues.put("goodsCode","12")
            contentValues.put("goodsDefaultIcon","1")
            contentValues.put("goodsDefaultPrice","1")
            contentValues.put("goodsDefaultSku","1")
            contentValues.put("goodsDesc","goodsDesc")
            contentValues.put("goodsDetailOne","goodsDetailOne")
            contentValues.put("goodsDetailTwo","goodsDetailTwo")
            contentValues.put("goodsSalesCount","goodsSalesCount")
            contentValues.put("goodsStockCount","goodsStockCount")
            contentValues.put("id",1)


            contentResolver.update(uri,contentValues,"id = ",  arrayOf("3"))
            contentResolver.insert(uri,contentValues)

            val query = contentResolver.query(uri, null, null, null, null)
            if(query != null){
                while (query.moveToNext()){
                    val categoryId = query.getInt(query.getColumnIndex("categoryId"))

                    println(categoryId)
                }
            }
        }

    }
}